package com.ctshk.sapp.insurance.controller;


import com.ctshk.common.dto.Result;
import com.ctshk.common.model.PageResponse;
import com.ctshk.common.model.TokenUser;
import com.ctshk.common.web.support.BaseController;
import com.ctshk.rpc.insurance.dto.InsuranceSellDTO;
import com.ctshk.rpc.insurance.req.InsuranceAdjustReq;
import com.ctshk.rpc.insurance.req.InsuranceSellReq;
import com.ctshk.rpc.insurance.service.IInsuranceProductService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 保险产品 前端控制器
 * </p>
 *
 * @author wangcy
 * @since 2021-01-26
 */
@Api(value = "产品中心保险", tags = "产品中心保险")
@RestController
@RequestMapping("/insurance-product")
public class InsuranceProductController extends BaseController {

    @DubboReference
    private IInsuranceProductService iInsuranceProductService;


    @ApiOperation(value = "保险售卖管理列表", notes = "保险售卖管理列表")
    @GetMapping(value = "queryAll")
    public Result<List<InsuranceSellDTO>> queryAll(@RequestParam(value = "ids", required = false) List<Long> ids) {

        return Result.success(iInsuranceProductService.queryAll(ids));
    }

    @ApiOperation(value = "保险售卖管理列表", notes = "保险售卖管理列表")
    @GetMapping(value = "query-list")
    public Result<PageResponse<InsuranceSellDTO>> queryList(@ModelAttribute InsuranceSellReq req) {
        return Result.success(iInsuranceProductService.queryList(req));
    }

    @ApiOperation(value = "保险加幅批量设置", notes = "保险加幅批量设置")
    @PostMapping(value = "batch-update-adjust")
    public Result<Long> updateAdjust(@RequestBody @Valid InsuranceAdjustReq req) {
        TokenUser currentUser = getCurrentUser();
        iInsuranceProductService.updateAdjust(req, currentUser.getId());
        return Result.success(req.getIds().get(0));
    }
}
